package cn.webrx;

import java.util.Scanner;

public class CustomerProcess {
	private Bank bank;

	public CustomerProcess(Bank bank) {
		this.bank = bank;
	}

	public String input() {
		Scanner input = new Scanner(System.in);
		return input.next();
	}
	public void process(String name) {
		while (true) {
			System.out.println("1、取钱2、存钱3、查看余额4、修改密码5、显示用户6、转账7、退出登入");
			String num = input();
			if ("1".equals(num)) {
				System.out.println("请输入要取的钱数：");
				double money= Double.parseDouble(input());
				String out=bank.outMomey(name, money);
				System.out.println(out);
			} else if ("2".equals(num)) {
				System.out.println("请输入要存的钱数：");
				double money= Double.parseDouble(input());
				String add=bank.addMomey(name, money);
				System.out.println(add);
			} else if ("3".equals(num)) {
				String show=bank.showMoney(name);
				System.out.println(show);
			} else if ("4".equals(num)) {
				System.out.println("请输入新密码：");
				String xipassword=input();
				String mod=bank.modCusMoney(name, xipassword);
				System.out.println(mod);
			}else if("5".equals(num)) {
				String all=bank.showAllCus(name);
				System.out.println(all);

			}else if("6".equals(num)) {
				System.out.println("请输入你要转账的用户名：");
				String tranifername=input();
				System.out.println("请输入你要转账的金额：");
				double money= Double.parseDouble(input());
				int a=bank.traniferout(name, money);
				boolean ff=bank.idName(tranifername);
				if(a==1) {
					int b=bank.traniferint(tranifername, money,ff);
					if(b==1) {
						System.out.println("-----转账成功-------");
					}else if(b==-1) {
						System.out.println("----转账失败,转账金额不符----");
					}else if(b==0) {
						System.out.println("----未找到该账户，转账失败----");
					}

				}else if(a==0) {
					System.out.println("----你的账户余额不足，请先存钱---");
				}else if(a==-1) {
					System.out.println("----转出失败，请重试----");
				}


			}else if ("7".equals(num)) {
				System.out.println("请你对本次服务做出评价：满意请按1；一般请按2；不满意请按0");
				String bak=input();
				if("1".equals(bak)) {
					System.out.println("感谢你的评价，谢谢使用本系统");
				}if("2".equals(bak)) {
					System.out.println("感谢你的评价，我们将会更加努力");
				}if("0".equals(bak)) {
					System.out.println("感谢你的评价,我们会尽快改正错误");
				}
				break;
			} else {
				System.out.println("=====请输入正确的选项=====");
			}
		}
	}
}
